package com.chii.colorization.utils.connes;

import com.chii.colorization.utils.connes.CookieStore;

import java.util.List;

import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.HttpUrl;

public class CookiesManager implements CookieJar {
    private CookieStore cookieStore;

    public CookiesManager(CookieStore cookieStore) {
        if(cookieStore == null) {
            throw new IllegalArgumentException("cookieStore can not be null.");
        }
        this.cookieStore = cookieStore;
    }
    @Override
    public synchronized  void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
        this.cookieStore.add(url, cookies);
    }

    @Override
    public synchronized  List<Cookie> loadForRequest(HttpUrl url) {
        return this.cookieStore.get(url);
    }
}